// @dart=2.12
import 'package:floor/floor.dart';
import 'package:flutter/cupertino.dart';
import 'package:ls_work/sql/protral/patrol_task_entity.dart';
import 'package:ls_work/sql/protral/patrol_task_point_entity.dart';

import 'offline_submit_patrol_entity.dart';

@dao
abstract class PatrolTaskDao {
  ///查找所有任务
  @Query('SELECT * FROM PatrolTaskData WHERE taskDate=:date')
  Future<List<PatrolTaskData>> findTodayTask(String date);

  @Query('SELECT * FROM PatrolTaskData')
  Future<List<PatrolTaskData>> findAllTask();

  ///根据任务id查询巡防点
  @Query('SELECT * FROM PatrolTaskPointData WHERE executeTaskId=:takId')
  Future<List<PatrolTaskPointData>> findPointByTask(int takId);


  ///根据任务id查询巡防点
  @Query('SELECT * FROM PatrolTaskPointData WHERE qrcode=:qrcode')
  Future<List<PatrolTaskPointData>> findPointByQrcode(String qrcode);

  ///获取巡防点详情
  @Query('SELECT * FROM PatrolTaskPointData WHERE id=:id')
  Future<PatrolTaskPointData?> taskPointDetail(int id);

  @Query('SELECT * FROM PatrolTaskPointData')
  Future<List<PatrolTaskPointData>> getAllTaskPoint();

  ///新增任务
  @insert
  Future<void> insertTask(PatrolTaskData task);

  ///新增任务巡防点
  @insert
  Future<void> insertTaskPoint(PatrolTaskPointData point);

  ///删除所有任务
  @Query("DELETE FROM PatrolTaskData")
  Future<void> deleteAllTask();

  ///删除所有任务巡防点
  @Query("DELETE FROM PatrolTaskPointData")
  Future<void> deleteAllPoint();

  ///更新任务巡防点
  @update
  Future<void> updateTaskPoint(PatrolTaskPointData point);

  ///保存本地提交记录
  @Insert(onConflict: OnConflictStrategy.replace)
  Future<void> saveLocalRecord(OfflineSubmitPatrolData data);

  ///删除本地记录
  @delete
  Future<void> deleteLocalRecord(OfflineSubmitPatrolData data);
  
  @Query('SELECT * FROM OfflineSubmitPatrolData')
  Future<List<OfflineSubmitPatrolData>> getLocalRecord();

  ///清除
  Future<void> deleteAll() async {
    await deleteAllPoint();
    await deleteAllTask();
  }


  @Insert(onConflict: OnConflictStrategy.ignore)
  Future<void> addTaskList(List<PatrolTaskData> list);

  @Insert(onConflict: OnConflictStrategy.ignore)
  Future<void> addTaskPointList(List<PatrolTaskPointData> list);


}
